'use strict';

/* Directives */


app.
    directive('appVersion', ['version', function(version) {
        return function(scope, elm, attrs) {
            elm.text(version);
        };
    }])
    .directive('ngReallyClick', [function() {
        return {
            restrict: 'A',
            link: function(scope, element, attrs) {
                element.bind('click', function() {
                    var message = attrs.ngReallyMessage;
                    if (message && confirm(message)) {
                        scope.$apply(attrs.ngReallyClick);
                    }
                });
            }
        }
    }]).directive('spFlash',
    function() {
        return {
            restrict : 'A',
            replace : true,
            template : '<div class="flash row-fluid">'

                + '<div class="flash-inner span4 offset4 alert alert-success" '

                + 'data-ng-repeat="msg in successMsg">{{msg}}</div>'

                + '</div>',

// If you are using twitter bootsrtap along with angular
//then you can use this classes span4 ,offset4 ,alert etc
//or you can define your own css for better look an feel.

            link : function($rootScope, scope, element, attrs) {
                $rootScope.successMsg = [];
                $rootScope.$watch('successMsg', function(val) {
                    if (val.length) {
                        update();
                    }
                }, true);

                function update() {
                    $('.flash')
                        .slideDown(500).delay(3000)
                        .slideUp(500, function() {
                            $rootScope.successMsg.splice(0);
                        });
                }
            }
        };
    }
);;
